/**
 * Created by kevin on 2017/6/2.
 */
function ucheck()
{

}

ucheck.hasLogin = function (res,callback) {
    let user = res.locals.user;
    if (callback) {
        callback(user);
    }
};

ucheck.isRoot = function (res,callback) {
    let user = res.locals.user;
    if (callback) {
        callback(user ? user.root : false);
    }
};

ucheck.AIManager = function (res,callback) {
    let user = res.locals.user;
    if (callback) {
        callback(user ? ((user.role && (user.role.permissions.managerA || user.role.permissions.managerI)) || user.root) : false);
    }
};

ucheck.IManager = function (res,callback) {
    let user = res.locals.user;
    if (callback) {
        callback(user ? ((user.role && (user.role.permissions.managerI)) || user.root) : false);
    }
};

ucheck.AManager = function (res,callback) {
    let user = res.locals.user;
    if (callback) {
        callback(user ? ((user.role && (user.role.permissions.managerA)) || user.root) : false);
    }
};

ucheck.canPackageIOSSync = function (res) {
    let user = res.locals.user;
    return (user ? ((user.role && (user.role.permissions.packageI || user.role.permissions.managerI)) || user.root) : false);
};

ucheck.canPackageAndroidSync = function (res) {
    let user = res.locals.user;
    return (user ? ((user.role && (user.role.permissions.packageA || user.role.permissions.managerA)) || user.root) : false);
};

ucheck.canPackageSync = function (res) {
    let user = res.locals.user;
    return (user ? ((user.role && (user.role.permissions.packageA || user.role.permissions.managerA || user.role.permissions.packageI || user.role.permissions.managerI)) || user.root) : false);
};

ucheck.canManagerIOSSync = function (res) {
    let user = res.locals.user;
    return (user ? ((user.role && (user.role.permissions.managerI)) || user.root) : false);
};

ucheck.canManagerAndroidSync = function (res) {
    let user = res.locals.user;
    return (user ? ((user.role && (user.role.permissions.managerA)) || user.root) : false);
};

ucheck.canManagerSync = function (res) {
    let user = res.locals.user;
    return (user ? ((user.role && ( user.role.permissions.managerA || user.role.permissions.managerI)) || user.root) : false);
};

ucheck.IPackager = function (res,callback) {
    let user = res.locals.user;
    if (callback) {
        callback(user ? ((user.role && (user.role.permissions.packageI || user.role.permissions.managerI)) || user.root) : false);
    }
};

ucheck.APackager = function (res,callback) {
    let user = res.locals.user;
    if (callback) {
        callback(user ? ((user.role && (user.role.permissions.packageA || user.role.permissions.managerA)) || user.root) : false);
    }
};

ucheck.AIPackager = function (res,callback) {
    let user = res.locals.user;
    if (callback) {
        callback(user ? ((user.role && (user.role.permissions.packageA || user.role.permissions.managerA || user.role.permissions.packageI || user.role.permissions.managerI)) || user.root) : false);
    }
};

ucheck.articleManager = function (res,callback) {
    let user = res.locals.user;
    if (callback) {
        callback(user ? ((user.role && (user.role.permissions.article)) || user.root) : false);
    }
};

ucheck.userChecker = function (res,callback) {
    let user = res.locals.user;
    if (callback) {
        callback(user ? ((user.role && (user.role.permissions.checkUser)) || user.root) : false);
    }
};

ucheck.isUser = function (username,res,callback) {
    let user = res.locals.user;
    if (callback) {
        callback(user && username === user.username);
    }
};

module.exports = ucheck;